<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Emp_license extends Page
{
       public $hfHint = null;
       public $edDue = null;
       public $Label5 = null;
       public $Label4 = null;
       public $lblop = null;
       public $lblli = null;
       public $Label12 = null;
       public $hfError = null;
       public $JSValidate = null;
       public $dpLicense = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $imgBack = null;
       public $lblempname = null;
       public $lblyear = null;
       public $Label48 = null;
       public $lblempid = null;
       public $hiddenEmp = null;
       public $edOpClass = null;
       public $edLicNum = null;
       public $JTSiteTheme1 = null;
       public $Label3 = null;
       public $Label2 = null;
       public $Label1 = null;
       public $Image3 = null;
       function edDueJSKeyUp($sender, $params)
       {

       ?>
       var numero = document.getElementById("edDue").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edDue").value = numero;

       <?php

       }

       function edOpClassJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edOpClass','lblop');
       <?php

       }

       function edLicNumJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edLicNum','lblli');
       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function btnCancelClick($sender, $params)
       {
       redirect('personnel_list.php?emp='.$this->hiddenEmp->getValue());


       }

       function validateRequired($value, $lbl)
       {
          if($value == '' || $value == null)
          {
             $this->$lbl->Caption = '&darr; This field is required &darr;';
             $this->hfError->setValue('1');
          }
       }

       function Emp_licenseCreate($sender, $params)
       {
       $this->hfError->setValue('0');
       $this->lblli->Caption = '';
       $this->lblop->Caption = '';

       $emp = $_GET['emp'];
       $hint = $_GET['hint'];
       $this->hiddenEmp->setValue($emp);
       $this->hfHint->setValue($hint);

       $query_emp = "select * from employee_tbl where autoid='".$this->hiddenEmp->getValue()."'";
       $result_emp = mysql_query($query_emp)or die(mysql_error());
       $row_emp = mysql_fetch_array($result_emp);

       $this->lblempid->Caption=$row_emp['emp_id'];
       $this->lblempname->Caption=$row_emp['lname'].','.$row_emp['fname'];


       $result_license = mysql_query("select * from emp_license_tbl where emp_id='".$this->hiddenEmp->getValue()."'");
       $row_license = mysql_fetch_array($result_license);

       $this->edLicNum->Text=$row_license['license_num'];
       $this->edOpClass->Text=$row_license['op_class'];
       $this->dpLicense->Text=$row_license['license_renew_date'];
       $this->edDue->Text=$row_license['days'];


       $this->imgBack->setLink('personnel_list.php?emp='.$this->hiddenEmp->getValue());

       }

       function btnSubmitClick($sender, $params)
       {
       $this->validateRequired($this->edLicNum->Text, 'lblli');
       $this->validateRequired($this->edOpClass->Text, 'lblop');
       $error = $this->hfError->getValue();
       if($error == '1' || $number != $key)
       {
          $this->hfError->setValue('0');
          return false;
       }
       else if($error == '0')
       {

      $result_license = mysql_query("select * from emp_license_tbl where emp_id='" . $this->hiddenEmp->getValue(). "'");
      $license_count = mysql_num_rows($result_license);
      if($license_count == 0)
      {
      $result = mysql_query("insert into emp_license_tbl (company_id,
       emp_id,
       license_num,
       op_class,
       license_renew_date,
       days)

       values ('".$_SESSION['company_id']."',
       '".$this->hiddenEmp->getValue()."',
       '".$this->edLicNum->Text."',
       '".$this->edOpClass->Text."',
       '".$this->dpLicense->Text."',
       '".$this->edDue->Text."')");
       }
       else
       {
       mysql_query("update emp_license_tbl set
       license_num = '".$this->edLicNum->Text."',
       op_class = '".$this->edOpClass->Text."',
       license_renew_date = '".$this->dpLicense->Text."',
       days = '".$this->edDue->Text."'
       where emp_id='".$this->hiddenEmp->getValue()."'")or die(mysql_error());
       }

       $hint_result = $this->hfHint->getValue();
       if($hint_result=='create')
       {
       echo"<script language=javascript>
       var answer = confirm('Add another personnel?');
       if(answer)
       {
       window.location = 'personnel_create.php';
       }
       else
       {
       window.location = 'personnel_list.php';
       }
       </script>";
       }

       if($hint_result=='edit')
       {
       echo"<script language=javascript>
       alert('Successfully Updated Record!');
       window.location = 'personnel_list.php';
       </script>";
       }


       //redirect('personnel_list.php?emp='.$this->hiddenEmp->getValue());
       }

       }

}

global $application;

global $Emp_license;

//Creates the form
$Emp_license=new Emp_license($application);

//Read from resource file
$Emp_license->loadResource(__FILE__);

//Shows the form
$Emp_license->show();

?>